package com.yunji.base.business;

import com.yunji.base.bo.MemberQueryBO;
import com.yunji.base.service.MemberService;
import com.yunji.common.base.BaseBusiness;
import com.yunji.common.model.domain.MemberDO;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.system.context.SystemContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.ArrayList;
import java.util.List;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.user.business
 * @Title: MemberBusiness
 * @Description: 顾客业务处理
 * <p>
 * History:
 * Date						Version			Author			Summary
 * ========================================================================
 * 2024-04-27 11:56:56		V1.0			HuaAo		新建类
 */
@Component
public class MemberBusiness extends BaseBusiness {


    @Autowired
    private MemberService memberService;

    public MemberDO selectMember() {
        return memberService.selectMember(SystemContext.getUserId());
    }

    public void updateMember(MemberDO member) {
        member.setId(SystemContext.getUserId());
        memberService.updateMember(member);
    }

    /**------------------------------------------搜索栏------------------------------------------*/

    /**
     * @param name 名字信息
     * @Title searchUserName
     * @Desc 名字匹配搜索
     * @Date 2024-09-09 14:10:47.166
     * @Return List<String> 匹配结果
     */
    public List<String> searchUserName(String name) {
        Assert.isTrue((name.length() <= 15), "输入用户昵称不合规");
        List<String> response = memberService.searchTableField(MemberQueryBO.builder()
                .phone(name).searchFiled("name").build());
        return BeanUtils.isNotNull(response) ? response : new ArrayList<>();
    }

    /**
     * @param phone 手机号码
     * @Title searchPhone
     * @Desc 手机号匹配搜索
     * @Date 2024-09-09 14:11:02.603
     * @Return List<String> 匹配信息
     */
    public List<String> searchPhone(String phone) {
        Assert.isTrue(phone.matches("^\\d{0,11}$"), "输入手机号不合规");
        List<String> response = memberService.searchTableField(MemberQueryBO.builder()
                .phone(phone).searchFiled("phone").build());
        return BeanUtils.isNotNull(response) ? response : new ArrayList<>();
    }
}